import {JsonController,Controller, Render, Get, UseBefore, Session,Req,Res,Ctx,QueryParams,UseInterceptor,Post,Body} from "routing-controllers";
import { config } from "../../config";
import { Service, Inject } from "typedi";
import {DynamicServiceImpl} from '../../service/impl/DynamicServiceImpl'
import TokenLoginMiddlewares from '../../middleware/TokenLoginMiddlewares';
import { JsonResponseInterceptor } from "../../middleware/JsonResponseMiddlewares";
import {DynamicModel,ChangeDynamicLike,SearchTagModel,DynamicNewsModel,DynamicInfoModel,ChangeDynamicCollection,getRecentVisitUserDataModel} from '../../model/DynamicModel'
import { utils } from "../../utils/utils";
@Service()
@JsonController(`${config.apiurl}/v1/dynamic`)
@UseInterceptor(JsonResponseInterceptor)
@UseBefore(TokenLoginMiddlewares)
export class DynamicControllerApi {



    @Inject()
    private DynamicServiceImpl!:DynamicServiceImpl;


    @Get("/getDynamicData")
    public async getDynamicData (@Res() response: any,@Session() session:any,@QueryParams() params:DynamicModel): Promise<any> {
        return await this.DynamicServiceImpl.getDynamicData(params);
    }


    
    @Get("/changeDynamicLike")
    public async changeDynamicLike (@Res() response: any,@Session() session:any,@QueryParams() params:ChangeDynamicLike): Promise<any> {
        return await this.DynamicServiceImpl.changeDynamicLike(params);
    }

    @Get("/changeDynamicCollection")
    public async changeDynamicCollection (@Res() response: any,@Session() session:any,@QueryParams() params:ChangeDynamicCollection): Promise<any> {
        return await this.DynamicServiceImpl.ChangeDynamicCollection(params);
    }

    @Get("/searchTag")
    public async searchTag (@Res() response: any,@Session() session:any,@QueryParams() params:SearchTagModel): Promise<any> {
        let result =  await this.DynamicServiceImpl.searchTag(params);
        if(result == '未找到相关话题'){
            return result;
        }
        return result;
    }

    @Get("/dynamicNew")
    public async dynamicNew (@Res() response: any,@Session() session:any,@QueryParams() params:DynamicNewsModel): Promise<any> {
        params.dynamic_Introduce = utils.utf16toEntities(params.dynamic_Introduce);
        return await this.DynamicServiceImpl.dynamicNew(params);

    }

    @Get("/dynamicInfo")
    public async dynamicInfo (@Res() response: any,@Session() session:any,@QueryParams() params:DynamicInfoModel): Promise<any> {
        return await this.DynamicServiceImpl.dynamicInfo(params);

    }

    @Get("/getRecentVisitUserData")
    public async getRecentVisitUserData (@Res() response: any,@Session() session:any,@QueryParams() params:getRecentVisitUserDataModel): Promise<any> {
        return{user_List:await this.DynamicServiceImpl.getRecentVisitUserData(params)} ;

    }
  }
  